home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16959 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  74 lines

  1. Path: vixen.cso.uiuc.edu!usenet
  2. From: Dragos-Anton Manolescu <manolesc@uiuc.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: HELP: STL adaptor problem (find_if + bind2nd)
  5. Date: 12 Apr 1996 16:11:26 -0500
  6. Organization: University of Illinois at Urbana-Champaign
  7. Message-ID: <opg2a9p2pt.fsf@sweetbay.will.uiuc.edu>
  8. Reply-To: Dragos Manolescu <manolesc@uiuc.edu>
  9. NNTP-Posting-Host: sweetbay.will.uiuc.edu
  10. X-Newsreader: Gnus v5.1
  11.  
  12.  
  13. Hello,
  14.  
  15. I'm trying to find an element in a vector and I ran into problems
  16. usign the bind2nd function adaptor. If I define the function as a
  17. binary function object, everything works fine:
  18.  
  19. struct MatchFirst : binary_function<Range,int,bool> {
  20.   bool operator() (const Range& a,const int& b) const
  21.   {
  22.     return a.r.first == b;
  23.   }
  24. } matchFirst;
  25.  
  26. and the call is:
  27.  
  28.       where = find_if(v.begin(),
  29.               v.end(),
  30.               bind2nd(matchFirst,i));
  31.  
  32. However, I tried to make the function object part of the class that it
  33. is supposed to work with (i.e. Range):
  34.  
  35. class Range {
  36. public:
  37. ...
  38.   class MatchFirst {
  39.   public:
  40.     bool operator()(Range&,int&) const;
  41.   };
  42. ...
  43. };
  44.  
  45. bool Range::MatchFirst::operator()(Range& a,int& b) const
  46. {
  47.   return a.r.first == b;
  48. }
  49.  
  50. with a call like this:
  51.  
  52.       where = find_if(v.begin(),
  53.               v.end(),
  54.               bind2nd(Range::MatchFirst(),i));
  55.  
  56. This time it fails to compile:
  57.  
  58. g++ -g -Wall   -c stltest.C -o stltest.o
  59. /usr/include/g++/function.h:193: `first_argument_type' is not a member of type `Range::MatchFirst'
  60. /usr/include/g++/function.h:194: `result_type' is not a member of type `Range::MatchFirst'
  61. /usr/include/g++/function.h:194: type/value mismatch in template parameter list for `template <class Arg, class Result> class unary_function'
  62. /usr/include/g++/function.h:194: type/value mismatch in template parameter list for `template <class Arg, class Result> class unary_function'
  63. /usr/include/g++/function.h:197: syntax error before `;'
  64. /usr/include/g++/function.h:200: confused by earlier errors, bailing out
  65. make: *** [stltest.o] Error 1
  66. make: Target `all' not remade because of errors.
  67.  
  68.  
  69. What am I doing wrong here? Please reply by e-mail if possible.
  70.  
  71. Thank you,
  72. -- 
  73. dam                                    http://www.uiuc.edu/ph/www/manolesc
  74.